
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}





const userList = [
  {
    userName: "xialuote",
    mobile: '18800008888',
    eMail: "xialuote@mail.com",
    gender: 1,
    state: 1,
    roles: ['admin'],
    c_time: '2020-01-02 12:01:20',
    name: "夏洛特",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/536/536.jpg",
  },
  {
    userName: "aguduo",
    mobile: '18800008888',
    eMail: "aguduo@mail.com",
    c_time: '2020-01-02 12:01:20',
    gender: 2,
    state: 1,
    roles: ['admin'],
    name: "阿古朵",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/533/533.jpg",
  },
  {
    userName: "mengtian",
    mobile: '18800008888',
    eMail: "mengtian@mail.com",
    gender: 1,
    c_time: '2020-01-02 12:01:20',
    state: 1,
    roles: ['admin'],
    name: "蒙恬",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/527/527.jpg",
  },
  {
    userName: "jing",
    mobile: '18800008888',
    eMail: "jing@mail.com",
    gender: 2,
    c_time: '2020-01-02 12:01:20',
    state: 1,
    roles: ['admin'],
    name: "镜",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/531/531.jpg",
  },
  {
    userName: "mengya",
    mobile: '18800008888',
    c_time: '2020-01-02 12:01:20',
    eMail: "mengya@mail.com",
    gender: 1,
    state: 1,
    roles: ['admin'],
    name: "蒙犽",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/524/524.jpg",

  },
  {
    userName: "lubandashi",
    mobile: '18800008888',
    eMail: "lubandashi@mail.com",
    c_time: '2020-01-02 12:01:20',
    gender: 1,
    state: 1,
    roles: ['admin'],
    name: "鲁班大师",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/525/525.jpg",

  },
  {
    userName: "xishi",
    mobile: '18800008888',
    eMail: "xishi@mail.com",
    gender: 1,
    c_time: '2020-01-02 12:01:20',
    state: 1,
    roles: ['admin'],
    name: "西施",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/523/523.jpg",
  },
  {
    userName: "machao",
    mobile: '18800008888',
    eMail: "machao@mail.com",
    gender: 1,
    c_time: '2020-01-02 12:01:20',
    state: 1,
    roles: ['admin'],
    name: "马超",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/518/518.jpg",
  },
  {
    userName: "yao",
    mobile: '18800008888',
    eMail: "yao@mail.com",
    c_time: '2020-01-02 12:01:20',
    gender: 1,
    state: 1,
    roles: ['admin'],
    name: "耀",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/522/522.jpg",
  },
  {
    userName: "yunzhongjun",
    mobile: '18800008888',
    eMail: "yunzhongjun@mail.com",
    gender: 1,
    c_time: '2020-01-02 12:01:20',
    state: 1,
    roles: ['admin'],
    name: "云中君",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/506/506.jpg",
  },
  {
    userName: "yao",
    mobile: '18800008888',
    eMail: "yao@mail.com",
    gender: 1,
    c_time: '2020-01-02 12:01:20',
    state: 1,
    roles: ['admin'],
    name: "瑶",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/505/505.jpg",
  },
  {
    userName: "change",
    mobile: '18800008888',
    c_time: '2020-01-02 12:01:20',
    eMail: "change@mail.com",
    gender: 1,
    state: 1,
    roles: ['admin'],
    name: "嫦娥",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/515/515.jpg",
  },
  {
    userName: "bailishouyue",
    mobile: '18800008888',
    eMail: "bailishouyue@mail.com",
    c_time: '2020-01-02 12:01:20',
    gender: 1,
    state: 1,
    roles: ['admin'],
    name: "百里守约",
    avatar: "https://game.gtimg.cn/images/yxzj/img201606/heroimg/196/196.jpg",
  },



]
userList.map((val, index) => {
  val.id = index + 1
})

const roles = [
  {
    id: 1,
    c_time: '2020-01-02 12:01:20',
    lable: "admin",
    title: "超级管理员",
    is_default:1
  },
  {
    id: 2,
    c_time: '2020-01-02 12:01:20',
    lable: "user",
    title: "普通用户",
    is_default:0

  },
  {
    id: 3,
    c_time: '2020-01-02 12:01:20',
    lable: "op",
    title: "运营管理",
    is_default:0

  },
]







module.exports = [
  // user login
  {
    url: '/consult-process/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/vue-admin-template/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  //get userList
  {
    url: '/vue-admin-template/user/getList\.*',
    type: 'get',
    response: config => {
      const { page = 1, limit = 10 } = config.query
      const list = [...userList].reverse();

      const index = (page - 1) * limit;
      const howmany = limit
      const data = list.splice(index, howmany)
      return {
        code: 20000,
        data: {
          lists: data,
          total: userList.length
        }
      }
    }
  },
  //deleteUser
  {
    url: '/vue-admin-template/user/deleteUser',
    type: 'post',
    response: config => {
      const { userName } = config.body
      const list = [...userList];
      const index = list.map(val => val.userName).indexOf(userName);
      if (index > -1) {
        userList.splice(index, 1)
        return {
          code: 20000,
          data: '删除成功'
        }
      }

      else {
        return {
          code: 40000,
          data: '删除成功'
        }
      }
    }
  },
  //deleteUser
  {
    url: '/vue-admin-template/user/create',
    type: 'post',
    response: config => {
      const { id } = config.body
      if (id) {
        let index = userList.map(val => val.id).indexOf(id)
        userList[index] = config.body

      } else {
        config.body.avatar = 'https://game.gtimg.cn/images/yxzj/img201606/heroimg/196/196.jpg'
        config.body.id = + new Date()
        config.body.c_time =  new Date().format('yyyy-mm-dd hh:mm:ss')
        userList.push(config.body)
      }
      return {
        code: 20000,
        data: !id ? '添加成功' : "修改成功"
      }



    }
  },
  //deleteUser
  {
    url: '/vue-admin-template/roles/getList\.*',
    type: 'get',
    response: config => {
      const { page = 1, limit = 10 } = config.query
      const list = [...roles].reverse();

      const index = (page - 1) * limit;
      const howmany = limit
      const data = list.splice(index, howmany)
      return {
        code: 20000,
        data: {
          lists: data,
          total: roles.length
        }
      }
    }
  },
  {
    url: '/vue-admin-template/roles/create',
    type: 'post',
    response: config => {
      let { id } = config.body
      config.body.id =  Number(id)

      if (id) {
        id = Number(id)
        const rolesList = [...roles]
        let index = rolesList.map(val => val.id).indexOf(id)
        roles[index] = config.body
      } else {
        config.body.id = + new Date()
        config.body.c_time =  new Date().format('yyyy-MM-dd hh:mm:ss')
        roles.push(config.body)
      }
      return {
        code: 20000,
        data: !id ? '添加成功' : "修改成功"
      }
    }
  },


]
